package de.sendorian.util.matcher;

import java.util.ArrayList;
import java.util.List;

/**
 * Matcher that matches Properties in JSP/ANT/Maven style "${foo}" or
 * JSF/SpEL style "#{bar}".
 * 
 * @author sendorian
 */
public class PropertyMatcher extends BlacklistMatcher<String> {

	protected static final List<Tuple> properties = new ArrayList<Tuple>();

	static {
		properties.add(new Tuple("${", "}"));
		properties.add(new Tuple("#{", "}"));
	}

	public PropertyMatcher() {
		super(properties);
	}

	@Override
	protected boolean matchesInternal(String string, Object property) {
		Tuple tuple = (Tuple) property;
		return string != null && string.trim().startsWith(tuple.begin)
				&& string.trim().endsWith(tuple.end);
	}

	
	/**
	 * Simple class that contains start and end of a string.
	 */
	private static class Tuple {
		private String begin;
		private String end;

		public Tuple(String begin, String end) {
			this.begin = begin;
			this.end = end;
		}
	}
}
